home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / NRPAS13 / CHEBFT.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-29  |  742b  |  30 lines

  1. PROCEDURE chebft(a,b: real; VAR c: glcarray; n: integer);
  2. (* Programs using the routine CHEBFT must define the type
  3. TYPE
  4.    glcarray=ARRAY [1..n] OF real;
  5. in the calling routine, and must externally define a function
  6. func(y:real):real which is to be analyzed. *)
  7. CONST
  8.    pi=3.141592653589793;
  9. VAR
  10.    k,j: integer;
  11.    y,fac,bpa,bma: real;
  12.    sum: double;
  13.    f: glcarray;
  14. BEGIN
  15.    bma := 0.5*(b-a);
  16.    bpa := 0.5*(b+a);
  17.    FOR k := 1 TO n DO BEGIN
  18.       y := cos(pi*(k-0.5)/n);
  19.       f[k] := func(y*bma+bpa)
  20.    END;
  21.    fac := 2.0/n;
  22.    FOR j := 1 TO n DO BEGIN
  23.       sum := 0.0;
  24.       FOR k := 1 TO n DO BEGIN
  25.          sum := sum+f[k]*cos((pi*(j-1))*((k-0.5)/n))
  26.       END;
  27.       c[j] := sngl(fac*sum)
  28.    END
  29. END;
  30.